/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.gob.fonafe.dao.impl.stored;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import oracle.jdbc.OracleTypes;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.StoredProcedure;
import pe.gob.fonafe.domain.GaleriaFotosBean;

/**
 *
 * @author Irving
 */
public class ListarGaleriaFotosByMuebleSP extends StoredProcedure{
    
    private static final String PROC_PARAM="USERGLC.P_OBTENER_GALERIA_MUEBLE";

    public ListarGaleriaFotosByMuebleSP(DataSource ds) {
        super(ds,PROC_PARAM);

        declareParameter(new SqlParameter("P_tb_Mueble_id_Mueble", Types.VARCHAR));
        declareParameter(new SqlOutParameter("cCURSOR", OracleTypes.CURSOR,new ListarGaleriaFotosMuebleRowMapper()));
    }

    public Map execute(String idMueble) {
        Map inputs = new HashMap();
        inputs.put("P_tb_Mueble_id_Mueble", idMueble);
        return super.execute(inputs);
    }

    private static class ListarGaleriaFotosMuebleRowMapper implements RowMapper<GaleriaFotosBean>{

        public GaleriaFotosBean mapRow(ResultSet rs, int rowNum) throws SQLException {
            GaleriaFotosBean bean = new GaleriaFotosBean();
            bean.setIdFotoGaleria(rs.getString("ID_GALERIAMUEBLE"));
            if(rs.getBlob("FOTO") != null){
                bean.setFoto(rs.getBlob("FOTO").getBytes(1, (int)rs.getBlob("FOTO").length()));
            }
            return bean;
        }
    }


}
